#include "fast_string_table.h"

//FastStringTable::FastStringTable() { }
//FastStringTable::~FastStringTable() { }

LexicUnitWithString * FastStringTable::GetUnit(int id) {
	for(int i = 0; i < this->GetCount(); i++)	{
		LexicUnitWithString * luws = table->GetData(i);
		if(luws->id == id)	return luws;
	}
	return NULL;
}


LexicUnitWithString * FastStringTable::GetUnit(char *str){
	for(int i = 0; i < this->GetCount(); i++)	{
		LexicUnitWithString *luws = table->GetData(i);
		if(strcmp(luws->name, str) == 0)	return luws;
	}
	return NULL;
}

LexicUnitWithString * FastStringTable::GetUnitAt(int index) {
	return table->GetData(index);
}

int FastStringTable::GetCount() {
	return table->GetCount();
}

bool FastStringTable::RemoveAt(int index) {
	return table->RemoveAt(index);
}

int FastStringTable::Add(char * str) {
	LexicUnitWithString * luws;
	luws = GetUnit(str);
	if(luws == NULL)	{
		luws = new LexicUnitWithString(this->GetCount(), str);
		table->Add(luws);
	}
	return luws->id;
}